[-*Smarty*-]
[-include file="$TPL_NAME/views/header.html"-]

[-* we want to include our stylesheet for this view*-]
<link rel="stylesheet" href="[-$TPL_STYLE_PATH-]/ajax_search.css" type="text/css">
<link rel="stylesheet" href="[-php-] echo $GLOBALS['assets_static_relative'] [-/php-]/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.min.css" type="text/css">

<script type="text/javascript" src="[-php-] echo $GLOBALS['assets_static_relative'] [-/php-]/jquery-min-3-1-1/index.js"></script>
<script type="text/javascript" src="[-php-] echo $GLOBALS['assets_static_relative'] [-/php-]/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.full.min.js"></script>

<!-- js for the popup window -->
<script type="text/javascript" src="[-php-] echo $GLOBALS['webroot'] [-/php-]/library/dialog.js?v=[-php-] echo $v_js_includes; [-/php-]"></script>

<!-- main navigation -->
[-*Load the Language Definitions*-]
[-config_load file="lang.$USER_LANG"-]

<!-- search parameters -->
<h2>[-php-] xl('Searching for appointments','e'); [-/php-]</h2>
&nbsp;
[-php-]
    echo "<a href='".$GLOBALS['webroot']."/interface/main/main_info.php' class='menu' onclick='top.restoreSession()'>";
[-/php-]
[-php-] xl('Return to calendar','e'); [-/php-]</a>
<div id="calsearch_params">
<form name="theform" id="theform" action="[-$FORM_ACTION-]" method="POST"> <!-- onsubmit="return top.restoreSession()"> -->
[-php-] xl('Keywords','e'); [-/php-]: <input type="text" name="pc_keywords" id="pc_keywords" value="[-php-]echo htmlspecialchars(strip_escape_custom($_POST['pc_keywords']),ENT_QUOTES);[-/php-]" />
<select name="pc_keywords_andor">
    <option value="AND">[-php-] xl('AND','e'); [-/php-]</option>
    <option value="OR">[-php-] xl('OR','e'); [-/php-]</option>
</select>
[-php-] xl('IN','e'); [-/php-]:
<select name="pc_category">
    <option value="">[-php-] xl('Any Category','e'); [-/php-]</option>
    [-$CATEGORY_OPTIONS-]
</select>
[-if $USE_TOPICS-]
<select name="pc_topic">
    <option value="">[-#_PC_SEARCH_ANY_TOPIC#-]</option>
    [-$TOPIC_OPTIONS-]
</select>
[-/if-]
<br>
[-php-] xl('between','e'); [-/php-]
<input type="text" class='datepicker' name="start" id="start" value="[-$DATE_START-]" size="10"/>
<input type="text" class='datepicker' name="end" id="end" value="[-$DATE_END-]" size="10"/>
<br>
[-php-] xl('for','e'); [-/php-]
<select name="provider_id" id="provider_id">
[-$PROVIDER_OPTIONS-]
</select>
[-php-] xl('at','e'); [-/php-]
<select name="pc_facility" id="pc_facility">
[-$FACILITY_OPTIONS-]
</select>
<input type="submit" name="submit" id="submit" value="[-php-] xl('Submit','e'); [-/php-]" />
<div id="calsearch_status"><img src='[-php-] echo $GLOBALS['webroot'] [-/php-]/interface/pic/ajax-loader.gif'> [-php-] xl('Searching...','e'); [-/php-]</div>
</form>
</div>
<!-- end of search parameters -->

[-if $SEARCH_PERFORMED-]
<div id="calsearch_results">

<div id="calsearch_results_header" class="head">
<table>
<tr>
<th class="calsearch_datetime">[-php-] echo xl('Date') . "-" . xl('Time'); [-/php-]</th>
<th class="calsearch_provider">[-php-] xl('Provider','e'); [-/php-]</th>
<th class="calsearch_category">[-php-] xl('Category','e'); [-/php-]</th>
<th class="calsearch_patient">[-php-] xl('Patient','e'); [-/php-]</th>
</tr>
</table>
</div>

<div id="calsearch_results_data">
<table>
[-php-]
/* I've given up on playing nice with the Smarty tag crap, it's pointlessly used
 * in the original search. I mean, there's no clean separation between the code
 * and HTML so we may as well just go full-bore PHP here -- JRM March 2008
 */

$eventCount = 0;
foreach ($this->get_template_vars('A_EVENTS') as $eDate => $date_events) {
    $eventdate = substr($eDate, 0, 4) . substr($eDate, 5, 2) . substr($eDate, 8, 2);

    foreach ($date_events as $event) {
        // pick up some demographic info about the provider
        $provquery = "SELECT * FROM users WHERE id='".$event['aid']."'";
        $res = sqlStatement($provquery);
        $provinfo = sqlFetchArray($res);

        $eData = $event['eid']."~".$eventdate;
        $trTitle = xl('Click to edit this event');
        echo "<tr class='calsearch_event' id='".$eData."' title='".$trTitle."'>";

        // date and time
        $eDatetime = strtotime($eDate." ".$event['startTime']);
        echo "<td class='calsearch_datetime'>";
        echo date("Y-m-d h:i a", $eDatetime);
        echo "</td>";

        // provider
        echo "<td class='calsearch_provider'>".$event['provider_name'];
        $imgtitle = $provinfo['fname'] . " " . xl('contact info') . ":\n";
        $imgtitle .= $provinfo['phonew1']."\n".$provinfo['street']."\n".$provinfo['city']." ".$provinfo['state'];
        echo " <img class'provinfo' src='".$GLOBALS['webroot']."/images/info.png' title=\"".$imgtitle."\" />";
        echo "</td>";

        // category
        echo "<td class='calsearch_category'>";
        echo $event['catname'];
        echo " </td>";

        // patient
        echo "<td class='calsearch_patient'>";
        echo $event['patient_name'];
        echo "</td>";
/*
        echo "<td>";
        print_r($event);
        echo "</td>";
*/
        echo "</tr>\n";

        $eventCount++;
    }
}


/* the A_EVENTS array holds an array of dates, which in turn hold the array of events
 * so it will always be non-zero, so we need to count the events as they are
 * displayed and if the count is zero, then we have no search results
 */
if ($eventCount == 0) {
    echo "<tr><td colspan='4' style='text-align: center'>" . xl('No Results') . "</td></tr>";
}

[-/php-]
</table>
</div>  <!-- end results-data DIV -->

</div>  <!-- end outer results DIV -->

[-/if-]  [-*end of SEARCH_PERFORMED*-]

<script language="javascript">
// jQuery stuff to make the page a little easier to use

$(document).ready(function(){
    $("#pc_keywords").focus();
    $("#theform").submit(function() { SubmitForm(this); });
    $(".calsearch_event").mouseover(function() { $(this).toggleClass("highlight"); });
    $(".calsearch_event").mouseout(function() { $(this).toggleClass("highlight"); });
    $(".calsearch_event").click(function() { EditEvent(this); });

    $('.datepicker').datetimepicker({
        [-php-] $datetimepicker_timepicker = false; [-/php-]
        [-php-] $datetimepicker_showseconds = false; [-/php-]
        [-php-] $datetimepicker_formatInput = false; [-/php-]
        [-php-] require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); [-/php-]
        [-php-] // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma [-/php-]
        ,format: 'm/d/Y'
    });
});

// open a pop up to edit the event
// parts[] ==>  0=eventID
var EditEvent = function (eObj) {
    objID = eObj.id;
    var parts = objID.split("~");
    dlgopen('add_edit_event.php?date='+ parts[1] +'&eid=' + parts[0], '_blank', 775, 500);
}

// show the 'searching...' status and submit the form
var SubmitForm = function(eObj) {
    $("submit").css("disabled", "true");
    $("#calsearch_status").css("visibility", "visible");
    return top.restoreSession();
}

function goPid(pid) {
    top.restoreSession();
    [-php-]
           echo "top.RTop.location = '../../patient_file/summary/demographics.php' " .
           			 "+ '?set_pid=' + pid;\n";
    [-/php-]
 }
</script>

[-*include file="$TPL_NAME/views/footer.html"*-]

